package org.gap.wizards.world.actions;

import java.util.List;

import org.gap.wizards.items.Inventory;
import org.gap.wizards.items.Item;
import org.gap.wizards.pc.PlayerCharacter;
import org.gap.wizards.views.InventorySelectionView;
import org.gap.wizards.views.MessageOutput;
import org.gap.wizards.world.WorldAction;

public class EquipItemAction implements WorldAction {
	private final PlayerCharacter pc;
	private final MessageOutput output;
	private final InventorySelectionView selection;

	public EquipItemAction(PlayerCharacter pc, MessageOutput output, InventorySelectionView selection) {
		this.pc = pc;
		this.output = output;
		this.selection = selection;
	}
	@Override
	public void perform() {
		List<Item> itemsWithFeature = pc.getInventory().itemsWithFeature(new Inventory.Feature() {
			@Override
			public boolean hasFeature(Item each) {
				return each.isEquipable();
			}
		});
		if (itemsWithFeature.isEmpty()) {
			output.addMessage("Nothing to equip");
			return;
		} else {
			output.addMessage("Select an item to equip?");
		}
		selection.setItems(itemsWithFeature);

		for (Item each : selection.getSelection()) {
			pc.getInventory().equipItem(each);
		}
	}
}
